//针对业务的不同请求进行处理
import axios from "./index";
import isLogin from './login'
import order from './order'
import report from './report'
//获取侧边栏菜单数据
let getMenus = () =>{
  return axios.get('/menus')
}
/* -----用户列表功能实现----- */
//获取用户列表
let getUsers = (params) =>{
  return axios.get('/users',params)
}
//修改用户状态
let changeUserState = userInfo =>{
  return axios.put(`users/${userInfo.id}/state/${userInfo.mg_state}`)
}
//添加用户
let addUser = (params) =>{
  return axios.post('users',params)
}
//根据ID查询用户信息
let getOneUser = (id) =>{
  return axios.get(`users/${id}`)
}
//编辑用户信息完成后提交
let finishEditUser = (id,params) =>{
  return axios.put('users/'+id,params)
}
//根据ID删除用户信息
let deleteOneUser = id =>{
  return axios.delete('users/' + id)
}
//分配用户职位
let setUserRoles = (userId,params) =>{
  return axios.put(`users/${userId}/role`,params)
}
//-------------------------------------------------
/* 权限管理功能实现 */
//获取所有权限数据(list形式)
let getRightsList = () =>{
  return axios.get('rights/list')
}
//获取所有权限数据(tree形式)
let getRightsTree = () =>{
  return axios.get('rights/tree')
}
//获取职位列表数据
let getRolesData = () =>{
  return axios.get('roles')
}
//删除职位权限
let deleteRolesRights = (rolesId,rightsId) =>{
  return axios.delete(`roles/${rolesId}/rights/${rightsId}`)
}
//给职位设置权限
let allotRights = (rolesId,params) =>{
  return axios.post(`roles/${rolesId}/rights`,params)
}
//--------------------------------------------------------
/* 商品管理功能的实现 */
//获取商品分类的数据
let getCategoryData = (params) =>{
  if (params)  return axios.get('categories',{params})
  return axios.get('categories')
 
}
//获取父级分类的数据
let getParentCateData = (params) =>{
  return axios.get('categories',params)
}
//添加商品类别
let addCategoryData = params =>{
  return axios.post('categories',params)
}

//---------------------------------------
/* 实现商品参数的一些功能 */

//根据id和sel选择是动态参数数据/静态属性数据
let getGoodsData = (id,params) =>{
  return axios.get(`categories/${id}/attributes`,params)
}

//添加参数
let addGoodsParams = (id,params) =>{
  return axios.post(`categories/${id}/attributes`,params)
}
//根据Id查询单个商品的参数
let getOneParams = (cateId,attrId,params) =>{
  return axios.get(`categories/${cateId}/attributes/${attrId}`,params)
}
//修改参数
let editGoodsParams = (cateId,attrId,params) =>{
  return axios.put(`categories/${cateId}/attributes/${attrId}`,params)
}
//删除商品参数
let deleteGoodsParams = (cateId,attrId) =>{
  return axios.delete(`categories/${cateId}/attributes/${attrId}`)
}
//添加商品参数属性
let addGoodsParamsAttr = (cateId,attrId,params) =>{
  return axios.put(`categories/${cateId}/attributes/${attrId}`,params)
}


//----------------------------------
//实现商品列表的一些功能
//获取商品列表数据
let getGoodsListData = (params) =>{
  return axios.get('goods',params)
}
//删除商品数据
let deleteGoodsData = (id) =>{
  return axios.delete(`goods/${id}`)
}
//添加商品数据
let addGoodsData = (params) =>{
  return axios.post('goods',params)
}





export default {
  isLogin,
  getMenus,
  getUsers,
  changeUserState,
  addUser,
  getOneUser,
  finishEditUser,
  deleteOneUser,
  getRightsList,
  getRolesData,
  deleteRolesRights,
  getRightsTree,
  allotRights,
  setUserRoles,
  getCategoryData,
  getParentCateData,
  addCategoryData,
  getGoodsData,
  addGoodsParams,
  getOneParams,
  editGoodsParams,
  deleteGoodsParams,
  addGoodsParamsAttr,
  getGoodsListData,
  deleteGoodsData,
  addGoodsData,
  //订单请求
  ...order,
  //图表请求
  ...report
}